package com.example.myfirstapp;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import controller.ActivityConllector;
import controller.BaseActivity;
import controller.TextAdapter;

public class DisplayMessageActivity extends BaseActivity {

    private String[] data = {
            "Name",
            "Sa",
            "Si",
            "Su",
            "Se",
            "So",
            "a",
            "i",
            "u",
            "e",
            "o",
            "Ka",
            "Ki",
            "Ku",
            "Ke",
            "Ko"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_message);

        // Get the Intent that started this activity and extract the string
        Intent intent = getIntent();
        String mes = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

        // Capture the layout's TextView and set the string as its text
        TextView textView = findViewById(R.id.textView);
        textView.setText(mes);

        // Toast Component
        Toast.makeText(DisplayMessageActivity.this, mes, Toast.LENGTH_SHORT).show();

        // list
        initialListView();

        // exit
        Button btn = (Button) findViewById(R.id.button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityConllector.finishAll();
            }
        });
    }


    public void initialListView() {
        TextAdapter adapter = new TextAdapter(
                DisplayMessageActivity.this,
                R.layout.list_view_item,
                data
        );

        ListView listView = (ListView) findViewById(R.id.list_selector);
        listView.setAdapter(adapter);
    }

    public static void actionStart(Context context, String EXTRA_MESSAGE, String mes) {

        Intent intent = new Intent(context, DisplayMessageActivity.class);
        intent.putExtra(EXTRA_MESSAGE, mes);
        context.startActivity(intent);

    }
}
